from pymongo import MongoClient

from utility.utils import get_args
from conf.settings import CLOUDMONITOR_MONGODB, CLOUDMONITOR_DB
from utility.log import Logger

logger = Logger().get_logger()

db = MongoClient(CLOUDMONITOR_MONGODB)[CLOUDMONITOR_DB]


def get_target_url(query):
    user = db.users.find_one(query)
    target_url_list = [item.get('targetUrl') for item in db.jobs.find({'uid': user['_id']}) if item.get('targetUrl')]

    return ','.join(target_url_list)


def main() -> int:
    args_dict = {
        '-u': 'username'
    }

    logger.info(f"Start {__file__}")
    query = {**get_args(args_dict)}
    target_url_list = get_target_url(query)
    print(target_url_list)

    logger.get_logger().info(f"End {__file__}")

    return 0


if __name__ == '__main__':
    main()

